<admintpl file="header" />
<link rel="stylesheet" href="__PUBLIC__/css/jquery.datetimepicker.css">
<style type="text/css">
	.hidden{
		display: none;
	}
	img.act_img {
	    height: 60px;
	}
</style>
</head>
<body>
	<div class="wrap">
		<!-- <ul class="nav nav-tabs">
			<li><a href="{:U('ad/index')}">{:L('ADMIN_AD_INDEX')}</a></li>
			<li class="active"><a href="{:U('ad/add')}">{:L('ADMIN_AD_ADD')}</a></li>
		</ul> -->
		<form method="post" class="form-horizontal" action="{:U('Admin/Activites/saveQueueBanner')}" enctype="multipart/form-data">
			<fieldset>
				<div class="control-group">
					<label class="control-label">商家名称</label>
					<div class="controls">
						<input type="text" name="searchName" id="shopname">
						<button class="shopSearch">查询</button>
						<select name="shopid" id="shop_list">
							<notempty name="banner[shopName]">
								<option value="{$banner[shopid]}" data-manage-shopid="{$banner[m_shopid]}" selected="selected">{$banner[shopName]}</option>
							</notempty>
						</select>
						<input type="hidden" name="manageShopId" value="{$banner[manageShopId]}">
						<input type="hidden" name="shopName" value="{$banner[shopName]}">
						<span class="form-required tips"></span>
					</div>
				</div>


				<div class="control-group">
					<label class="control-label">应用范围</label>
					<div class="controls">
						<input type="checkbox" name="type" value="1" <eq name="banner['type']" value='1'>checked</eq> />
						全部商家
					</div>
				</div>

				<div class="control-group">
					<label class="control-label">banner图片</label>
					<div class="controls">
						 <input type="file" name="image">
						<span class="form-required">*</span>
						<notempty name="banner[image]"><img src="{$banner[image]}" width="100px"></notempty>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">分享标题</label>
					<div class="controls">
						<input type="text" name="shareTitle" value="{$banner['shareTitle']}">
						<span class="form-required">*</span>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">分享描述</label>
					<div class="controls">
						<input type="text" name="shareDesc" value="{$banner['shareDesc']}">
						<span class="form-required">*</span>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">链接地址</label>
					<div class="controls">
						<input type="text" name="link" value="{$banner['link']}">
						<span class="form-required">*</span>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">活动标题</label>
					<div class="controls">
						<input type="text" name="title" value="{$banner['title']}">
						<span class="form-required">*</span>
					</div>
				</div>
				<notempty name="banner[id]"><input name="id" type="hidden" value="{$banner['id']}"/></notempty>
				<notempty name="banner[image]"><input name="image" type="hidden" value="{$banner['image']}"/></notempty>
				<notempty name="banner[status]"><input name="status" type="hidden" value="{$banner['status']}"/></notempty>

			</fieldset>
			<div class="form-actions">
				<button type="submit" class="btn btn-primary js-ajax-submit">{:L('ADD')}</button>
				<a class="btn" href="{:U('Activites/listQueueBanner')}">{:L('BACK')}</a>
			</div>
		</form>
	</div>
	<script src="__PUBLIC__/js/common.js"></script>
  <script src="__PUBLIC__/js/laydate.js"></script>
  <script>
	  $(function(){


		  $('.shopSearch').click(function(){
			  var shopname = $('input[name="searchName"]').val();
			  $("#shop_list").html('');
			  $.ajax({
				  url:'/index.php?g=admin&m=activites&a=searchShop',
				  type:"POST",
				  data:{shopName:shopname},
				  dataType:"JSON",
				  success:function(data){
					  console.log(data);
					  if(data.shops.length>0) $("#shop_list").html('');
					  $.each(data.shops,function(id,shop){
						  var htm = '<option value="'+shop.shopId +'" data-manage-shopid="'+ shop.manageShopId +'">'+ shop.shopName+'(' + shop.branchName +')</option>';
						  $('input[name="manageShopId"]').val(shop.manageShopId);
						  $('input[name="shopName"]').val(shop.shopName+'(' + shop.branchName +')');
						  $("#shop_list").append(htm);
						  console.log(htm);
					  });
				  }});
			  return false;
		  });
		  $('#shop_list').change(function(data){
			  var mid = $('#shop_list option[value="' + $(this).val() +'"]').attr('data-manage-shopid');
			  var shopname = $('#shop_list option[value="' + $(this).val() +'"]').text();
			  $('input[name="manageShopId"]').val(mid);
			  $('input[name="shopName"]').val(shopname);
			  console.log($(this).val() + "   "+ shopname);
		  });

		  $('.citySearch_2').click(function(){
			  var cityname = $('input[name="citySearch_2"]').val();
			  var sel = document.getElementById('citySelectList_2');
			  var isMatch = 0;
			  if(cityname.trim() == ''){
				  $('#citySelectList_2 option').show();
				  return false;
			  }
			  $('#citySelectList_2 option').each(function(){
				  var city = $(this).text();
				  var city_val = $(this).val();
				  if(city.indexOf(cityname) == -1){
					  $(this).hide();
				  }else{
					  $(this).show();
					  if(!isMatch) $('#citySelectList_2').val(city_val);
					  isMatch = 1;
					  console.log($(this).text());
				  }
			  });
			  if(!isMatch){
				  $('#citySelectList_2 option').eq(0).show();
				  $('#citySelectList_2').val(0);
			  }
			  return false;

		  });
	  });

  </script>
</body>
</html>